package com.bjh.service.impl;

import com.bjh.dao.SaleDao;
import com.bjh.service.SaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
public class SaleServiceImpl implements SaleService {
    @Autowired
    private SaleDao saleDao;
    /**
     * 通过代理商id获取销售人员
     * @param params 相关参数
     * @return {@link List}
     * @throws Exception Exception
     */
    @Override
    public List<?> getSaleByAgentId(Map<String, Object> params) throws Exception {
        return saleDao.getSaleByAgentId(params);
    }

    /**
     * 通过代理商id分页获取销售人员
     * @param params 相关参数
     * @return {@link List}
     * @throws Exception Exception
     */
    @Override
    public Map<String, Object> getSaleOfPageByAgentId(Map<String, Object> params) throws Exception {
        Map<String, Object> resMap = new HashMap<>();
        resMap.put("list", saleDao.getSaleOfPageByAgentId(params));
        resMap.put("count", saleDao.getSaleCountByAgentId(params));
        return resMap;
    }

    /**
     * 获取销售人员详情
     * @param id 销售人员id
     * @return {@link Map}
     * @throws Exception Exception
     */
    @Override
    public Map<String, Object> getSaleById(Long id) throws Exception {
        return saleDao.getSaleById(id);
    }

    /**
     * 编辑销售人员
     * @param params 相关参数
     * @throws Exception Exception
     */
    @Override
    public void editSale(Map<String, Object> params) throws Exception {
        if(Objects.isNull(params.get("id"))){
            saleDao.addSale(params);
        }else {
            saleDao.updateSale(params);
        }
    }
}
